package com.ruoyi.customerService.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.customerService.domain.CsCustomerComplaintSheetBill;
import com.ruoyi.customerService.domain.CsSheetHandleQuality;
import com.ruoyi.customerService.domain.vo.CsCustomerComplaintSheetBillVo;
import com.ruoyi.customerService.domain.vo.CsSheetHandleQualityVo;
import com.ruoyi.customerService.service.CsCustomerComplaintSheetBillService;
import com.ruoyi.customerService.service.CsSheetHandleQualityService;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cs/sheetHandle")
@Api(tags = "客服中心-工单处理质量统计")
public class CsSheetHandleQualityController {
    @Autowired
    private CsSheetHandleQualityService csSheetHandleQualityService;
    @Autowired
    private TableService tableService;

    @ApiOperation("汇总")
    @PostMapping("collect")

    public R collect(@RequestBody CsSheetHandleQualityVo vo){
        List<CsSheetHandleQuality> bills = csSheetHandleQualityService.collect(vo);
        if (bills == null || bills.size() == 0){
            return R.fail("暂无数据");
        }else {
            JSONObject jsonObject = new JSONObject();
            String[] fields = {"networkName", "contractAreaName", "sheetChannel", "sheetType"
                    , "hqSolicitor", "firstTimeoutRate", "firstTimeoutNum", "handleTimeoutRate"
                    , "handleTimeoutNum", "complaintRate", "sheetCompletionRate", "oneTimeResolutionRate"
                    , "avgHandlePeriod", "avgFirstPeriod"};
            InitTableVo initTableVo = new InitTableVo();
            initTableVo.setFields(fields);
            initTableVo.setCode("csSheetHandleQuality");
            jsonObject.put("list",PageInfo.info(bills));
            jsonObject.put("fields", tableService.initTable(initTableVo));
            return R.ok(jsonObject);
        }
    }

}
